//
//  ViewController.m
//  进度圈
//
//  Created by able on 17/1/11.
//  Copyright © 2017年 able. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (strong, nonatomic) CAShapeLayer *backgroundCycle1;
@property (strong, nonatomic) CAShapeLayer *backgroundCycle2;
@property (strong, nonatomic) CAShapeLayer *backgroundCycle3;


@property (strong, nonatomic) CAShapeLayer *progressCycle;

@property (strong, nonatomic) UIBezierPath *path1;
@property (strong, nonatomic) UIBezierPath *path2;
@property (strong, nonatomic) UIBezierPath *path3;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self.view.layer addSublayer:self.backgroundCycle1];
    [self.view.layer addSublayer:self.backgroundCycle2];
    [self.view.layer addSublayer:self.backgroundCycle3];

    [self setAnimateWithProgress:0.8];

}
- (void)setAnimateWithProgress:(CGFloat)progress {
    CABasicAnimation *animate = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    animate.fromValue = @0;
    animate.byValue = [NSNumber numberWithFloat:progress];
    animate.duration = 2;
    animate.fillMode = kCAFillModeForwards;
    animate.removedOnCompletion = NO;
    [self.progressCycle addAnimation:animate forKey:nil];
    [self.view.layer addSublayer:self.progressCycle];
    
}

- (CAShapeLayer *)backgroundCycle1 {
    if (!_backgroundCycle1) {
        _backgroundCycle1 = [CAShapeLayer layer];
        _backgroundCycle1.path = self.path1.CGPath;
        _backgroundCycle1.lineWidth = 8.0f;
        _backgroundCycle1.fillColor = [UIColor clearColor].CGColor;
        _backgroundCycle1.strokeColor = [UIColor grayColor].CGColor;
    }
    return _backgroundCycle1;
}
-(CAShapeLayer *)backgroundCycle2{
    if (!_backgroundCycle2) {
        _backgroundCycle2=[CAShapeLayer layer];
        _backgroundCycle2.path=self.path2.CGPath;
        _backgroundCycle2.lineWidth=5.0f;
        _backgroundCycle2.fillColor=[[UIColor clearColor] CGColor];
        _backgroundCycle2.strokeColor=[[UIColor redColor] CGColor];
    }
    return _backgroundCycle2;
}
- (CAShapeLayer *)backgroundCycle3 {
    if (!_backgroundCycle3) {
        _backgroundCycle3 = [CAShapeLayer layer];
        _backgroundCycle3.path = self.path3.CGPath;
        _backgroundCycle3.lineWidth = 5.0f;
        _backgroundCycle3.fillColor = [UIColor clearColor].CGColor;
        _backgroundCycle3.strokeColor = [UIColor greenColor].CGColor;
    }
    return _backgroundCycle3;
}

- (CAShapeLayer *)progressCycle {
    if (!_progressCycle) {
        _progressCycle = [CAShapeLayer layer];
        _progressCycle.path = self.path1.CGPath;
        _progressCycle.lineWidth = 8.0f;
        _progressCycle.lineCap = kCALineCapRound;
        _progressCycle.fillColor = [UIColor clearColor].CGColor;
        _progressCycle.strokeColor = [UIColor orangeColor].CGColor;
    }
    return _progressCycle;
}

- (UIBezierPath *)path1 {
    if (!_path1) {
        _path1 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(200, 200) radius:51.5 startAngle:-M_PI_2 endAngle:(2*M_PI-M_PI_2) clockwise:YES];
    }
    return _path1;
}
- (UIBezierPath *)path2 {
    if (!_path2) {
        _path2 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(200, 200) radius:45 startAngle:-M_PI_2 endAngle:(2*M_PI-M_PI_2) clockwise:YES];
    }
    return _path2;
}
- (UIBezierPath *)path3 {
    if (!_path3) {
        _path3 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(200, 200) radius:40 startAngle:-M_PI_2 endAngle:(2*M_PI-M_PI_2) clockwise:YES];
    }
    return _path3;
}





@end
